package com.autoool;

import java.util.HashMap;
import java.util.Map;
import java.util.Objects;

/**
 * @author sam
 * 2021/7/8 21:02
 * @description
 * @editor
 * @description
 */
public class KeylessEntity {

    static class Key {
        Integer id;

        Key(Integer id) {
            this.id = id;
        }

        @Override
        public int hashCode() {
            return id.hashCode();
        }

        @Override
        public boolean equals(Object o) {
            if (this == o) return true;
            if (o == null || getClass() != o.getClass()) return false;
            Key key = (Key) o;
            return Objects.equals(id, key.id);
        }
    }

    public static void main(String[] args) {
        Key key1 = new Key(1);
        Key key2 = new Key(1);
        System.out.println(key1.hashCode());
        System.out.println(key2.hashCode());
        Map m = new HashMap();
        m.put(key1,"1");
        System.out.println(m.containsKey(key2));

//        while (true) {
//            for (int i = 0; i < 10000; i++) {
//                if (!m.containsKey(new Key(i))) {
//                    m.put(new Key(i), "number: " + i);
//                }
//            }
//            System.out.println(" " + m.size());
//        }
    }
}
